<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\manystore\model\ManystoreShop;

/**
 * 大额券管理
 *
 * @icon fa fa-circle-o
 */
class Coupon extends Backend
{

    /**
     * Coupon模型对象
     * @var \app\admin\model\Coupon
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Coupon;
        $this->view->assign("statusList", $this->model->getStatusList());
    }
    public function examine($ids="",$type="")
    {
        $shopModel = new ManystoreShop();
        if($type==1){
            //激活
            $find=$this->model->where(['id'=>$ids])->find();
            $where_shop['type']=$find['shop_type'];
            $where_shop['status']=1;
            $shop_list=$shopModel->where($where_shop)->field('id')->select();
            $shop_data=[];
            foreach ($shop_list as $k=>$shop){
                $shop_data[$k]['coupon_id']=$ids;
                $shop_data[$k]['shop_id']=$shop['id'];
            }
            db('coupon_shop')->insertAll($shop_data);

        }else{

        }
        $where['id']=$ids;
        $this->model->save(['status'=>$type],$where);
        $this->success('成功');
    }
}
